{  Statement: http://acmp.ru/?main=task&id_task=47
   Verdict: Accepted
}
uses
    SysUtils, Math;

var
    i,n,cc,kk,j:longint;
    a,b:array[0..1010] of longint;
    f:boolean;

function get(n:longint):longint;
begin
result := 0;
while n > 0 do begin
    inc(result, n mod 10);
    n := n div 10;
end;
end;

begin
reset(input,'input.txt');
rewrite(output,'output.txt');
read(n);
kk := trunc(sqrt(n));
cc := 0;
for i:=1 to kk do
    if n mod i = 0 then begin
        inc(cc);
        a[cc] := i;
                b[cc] := get(i);
                if i * i <> n then begin
                    inc(cc);
                    a[cc] := n div i;
                    b[cc] := get(n div i);
                end;
    end;
for i:=1 to cc do begin
    f := true;
    for j:=1 to cc do begin
        if i = j then continue;
        if not((b[i] > b[j]) or ((b[i] = b[j]) and (a[i] < a[j]))) then begin
            f := false;
            break;
        end;
    end;
    if f then begin
        write(a[i]);
        halt(0);
    end;
end;
end.